package com.example.exception;

/**
 * 业务异常类
 * 用于处理业务逻辑相关的异常
 */
public class BusinessException extends BaseException {
    
    public BusinessException(String errorCode, String errorMessage) {
        super(errorCode, errorMessage, ErrorCategory.BUSINESS);
    }
    
    public BusinessException(String errorCode, String errorMessage, Object errorDetails) {
        super(errorCode, errorMessage, errorDetails);
        setErrorCategory(ErrorCategory.BUSINESS);
    }
    
    public BusinessException(String errorCode, String errorMessage, Throwable cause) {
        super(errorCode, errorMessage, cause);
        setErrorCategory(ErrorCategory.BUSINESS);
    }
    
    // ========== 用户相关业务异常 ==========
    
    public static BusinessException userNotFound() {
        return new BusinessException(ErrorCode.USER_NOT_FOUND, "用户不存在");
    }
    
    public static BusinessException userNotFound(String username) {
        return new BusinessException(ErrorCode.USER_NOT_FOUND, "用户不存在: " + username);
    }
    
    public static BusinessException userAlreadyExists() {
        return new BusinessException(ErrorCode.USER_ALREADY_EXISTS, "用户已存在");
    }
    
    public static BusinessException userAlreadyExists(String username) {
        return new BusinessException(ErrorCode.USER_ALREADY_EXISTS, "用户已存在: " + username);
    }
    
    public static BusinessException userPasswordError() {
        return new BusinessException(ErrorCode.USER_PASSWORD_ERROR, "密码错误");
    }
    
    public static BusinessException userDisabled() {
        return new BusinessException(ErrorCode.USER_DISABLED, "用户已被禁用");
    }
    
    public static BusinessException userLocked() {
        return new BusinessException(ErrorCode.USER_LOCKED, "用户已被锁定");
    }
    
    // ========== 权限相关业务异常 ==========
    
    public static BusinessException permissionDenied() {
        return new BusinessException(ErrorCode.PERMISSION_DENIED, "权限不足");
    }
    
    public static BusinessException permissionDenied(String operation) {
        return new BusinessException(ErrorCode.PERMISSION_DENIED, "权限不足，无法执行操作: " + operation);
    }
    
    public static BusinessException roleNotFound() {
        return new BusinessException(ErrorCode.ROLE_NOT_FOUND, "角色不存在");
    }
    
    public static BusinessException roleNotFound(String roleName) {
        return new BusinessException(ErrorCode.ROLE_NOT_FOUND, "角色不存在: " + roleName);
    }
    
    public static BusinessException menuNotFound() {
        return new BusinessException(ErrorCode.MENU_NOT_FOUND, "菜单不存在");
    }
    
    public static BusinessException menuAccessDenied() {
        return new BusinessException(ErrorCode.MENU_ACCESS_DENIED, "菜单访问被拒绝");
    }
    
    // ========== 数据相关业务异常 ==========
    
    public static BusinessException dataNotFound() {
        return new BusinessException(ErrorCode.DATA_NOT_FOUND, "数据不存在");
    }
    
    public static BusinessException dataNotFound(String dataType) {
        return new BusinessException(ErrorCode.DATA_NOT_FOUND, dataType + "不存在");
    }
    
    public static BusinessException dataAlreadyExists() {
        return new BusinessException(ErrorCode.DATA_ALREADY_EXISTS, "数据已存在");
    }
    
    public static BusinessException dataAlreadyExists(String dataType) {
        return new BusinessException(ErrorCode.DATA_ALREADY_EXISTS, dataType + "已存在");
    }
    
    public static BusinessException dataValidationFailed(String message) {
        return new BusinessException(ErrorCode.DATA_VALIDATION_FAILED, "数据验证失败: " + message);
    }
    
    public static BusinessException dataSaveFailed() {
        return new BusinessException(ErrorCode.DATA_SAVE_FAILED, "数据保存失败");
    }
    
    public static BusinessException dataUpdateFailed() {
        return new BusinessException(ErrorCode.DATA_UPDATE_FAILED, "数据更新失败");
    }
    
    public static BusinessException dataDeleteFailed() {
        return new BusinessException(ErrorCode.DATA_DELETE_FAILED, "数据删除失败");
    }
    
    // ========== 文件相关业务异常 ==========
    
    public static BusinessException fileNotFound() {
        return new BusinessException(ErrorCode.FILE_NOT_FOUND, "文件不存在");
    }
    
    public static BusinessException fileUploadFailed() {
        return new BusinessException(ErrorCode.FILE_UPLOAD_FAILED, "文件上传失败");
    }
    
    public static BusinessException fileSizeExceeded() {
        return new BusinessException(ErrorCode.FILE_SIZE_EXCEEDED, "文件大小超出限制");
    }
    
    public static BusinessException fileTypeNotSupported() {
        return new BusinessException(ErrorCode.FILE_TYPE_NOT_SUPPORTED, "不支持的文件类型");
    }
    
    // ========== 聊天相关业务异常 ==========
    
    public static BusinessException chatMessageSendFailed() {
        return new BusinessException(ErrorCode.CHAT_MESSAGE_SEND_FAILED, "消息发送失败");
    }
    
    public static BusinessException chatUserNotOnline() {
        return new BusinessException(ErrorCode.CHAT_USER_NOT_ONLINE, "用户不在线");
    }
    
    public static BusinessException chatPermissionDenied() {
        return new BusinessException(ErrorCode.CHAT_PERMISSION_DENIED, "聊天权限不足");
    }
}
